﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
/// <summary>
/// Check 的摘要说明
/// </summary>
public class Check
{
    public Check()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    #region 检查管理员是否有指定的权限---  功 能
    /// <summary>
    /// 检查管理员是否有指定的权限
    /// </summary>
    /// <param name="FUNC_CODE">权限 id</param>

    public static void CheckPermission(string funccode)
    {

        if (HttpContext.Current.Session["Functions"] != null)
        {
            Hashtable table = (Hashtable)HttpContext.Current.Session["Functions"];
            if (!table.ContainsValue(funccode))
            {
                HttpContext.Current.Response.Redirect(BLL.Common.GetWebPath() + "/login.htm");
            }
        }
        else
        {
            HttpContext.Current.Response.Redirect(BLL.Common.GetWebPath() + "/login.htm");
        }


    }
    #endregion

    #region 检查管理员是否有指定的权限---  操 作
    /// <summary>
    /// 检查管理员是否有指定的权限
    /// </summary>
    /// <param name="Operate">权限 id</param>

    public static bool CheckPermission(string funccode, string operatecode)
    {
        if (HttpContext.Current.Session["Users"] == null)
        {
            return false;
        }
        else
        {
            string[] users = (string[])HttpContext.Current.Session["Users"];
            if (users[2].IndexOf("000") != -1)
            {
                return true;
            }
            else
            {
                if (HttpContext.Current.Session["Operates"] != null)
                {
                    DataTable table = (DataTable)HttpContext.Current.Session["Operates"];
                    table.DefaultView.RowFilter = "FUNCCODE=" + funccode;
                    DataTable dt0 = table.DefaultView.ToTable();
                    for (int i = 0; i < dt0.Rows.Count; i++)
                    {
                        if (dt0.Rows[i]["OPERATECODE"].ToString() == operatecode)
                        {
                            return true;
                        }
                    }
                    return false;
                }
                else
                {
                    return false;
                }
            }
        }
    }

    #endregion



}
